//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.goldhuman.IO.Protocol;

import com.goldhuman.Common.Runnable;
import com.goldhuman.Common.ThreadPool;
import com.goldhuman.IO.PollIO;

public final class Task extends Runnable {
    private Manager manager;
    private Session session;
    private Protocol protocol;
    private long time_start = 0L;

    private Task(int priority, Manager _manager, Session _session, Protocol _protocol) {
        super(priority);
        this.manager = _manager;
        this.session = _session;
        this.protocol = _protocol;
        this.time_start = System.currentTimeMillis();
    }

    public void run() {
        try {
            this.protocol.time_wait = System.currentTimeMillis() - this.time_start;
            this.protocol.Process(this.manager, this.session);
            if (Session.need_wakeup) {
                PollIO.WakeUp();
                Session.need_wakeup = false;
            }
        } catch (ProtocolException var2) {
            System.out.println("jio exception type=" + this.protocol.getType() + "," + var2.toString());
            this.manager.Close(this.session);
        }

    }

    protected static void Dispatch(Manager manager, Session session, Protocol protocol) {
        int priority = manager.PriorPolicy(protocol.type);
        Task task = new Task(priority, manager, session, protocol);
        if (priority > 0) {
            ThreadPool.AddTask(task);
        } else {
            session.AddTask(task);
        }

    }
}
